/**
 * 
 */
package com.ez.supervise.service.impl;

import java.util.List;

import com.ez.supervise.dao.RolePermissionDao;
import com.ez.supervise.model.sys.RolePermission;
import com.ez.supervise.service.RolePermissionService;

/**
 * @author searph.wang
 * @email searph.wang@gmail.com
 * @Created at 2009-7-22
 * 
 */
public class RolePermissionServiceImpl implements RolePermissionService {
    private RolePermissionDao rolePermissionDao;

    // public int update(RolePermission rolePermission) {
    // return sqlMapClientTemplate.update("sys.updateRolePermission",
    // rolePermission);
    // }

    public void setRolePermissionDao(RolePermissionDao rolePermissionDao) {
	this.rolePermissionDao = rolePermissionDao;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.ez.supervise.service.base.BaseService#delete(java.lang.Long)
     */
    public void delete(Long id) {
	// TODO Auto-generated method stub
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.ez.supervise.service.base.BaseService#insert(java.lang.Object)
     */
    public void insert(Object entity) {
	rolePermissionDao.insert(entity);

    }

    /*
     * (non-Javadoc)
     * 
     * @see com.ez.supervise.service.base.BaseService#update(java.lang.Object)
     */
    public void update(Object entity) {
	rolePermissionDao.update(entity);
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.ez.supervise.service.base.BaseService#get(java.lang.Long)
     */
    public Object get(Long id) {
	return (RolePermission) rolePermissionDao.get(id);
    }

    public List findPermissionByRoleId(Long roleId) {
	return rolePermissionDao.findPermissionByRoleId(roleId);
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.ez.supervise.service.RolePermissionService#saveRolePermissionByRoleId
     * (java.lang.Long, java.lang.Long[])
     */
    public void saveRolePermissionByRoleId(Long roleId, Long[] id) {
	rolePermissionDao.deleteRolePermissionByRoleId(roleId);
	RolePermission rp = null;
	for (Long pId : id) {
	    rp = new RolePermission(roleId, pId);
	    rolePermissionDao.insert(rp);
	}
    }
}
